package cn.zktr.Personnel.model.service.zhouyongcong;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.zktr.Personnel.model.dao.zhouyongcong.PmsDeptDao;
import cn.zktr.Personnel.model.dao.zhouyongcong.PmsEmpDao;
import cn.zktr.Personnel.model.dao.zhouyongcong.PmsPesDao;
import cn.zktr.Personnel.model.pojos.PerKnoWle;
import cn.zktr.Personnel.model.pojos.PerPmsDept;
import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.pojos.PerPmsPes;
import cn.zktr.Personnel.model.uitls.Authority;
import cn.zktr.Personnel.model.uitls.Homapape;
import cn.zktr.Personnel.model.uitls.Wle;

@Service
@Transactional(rollbackFor=Exception.class)
public class getUitlsService {
	@Autowired
	private PmsEmpDao ped;
	@Autowired
	private PmsPesDao ppd;
	@Autowired
	private PmsDeptDao pdd;
	
	/**部门列表
	 * @return
	 */
	public List<PerPmsDept> selectDept() {
		return  (List<PerPmsDept>)pdd.findAll();
	}
	
	/**调试员可以访问的权限页面信息
	 * @param empid 
	 * @return
	 */
	public List<Authority> getAuthority() {
		Iterable<PerPmsPes> findid = ppd.findAll();
		Homapape hopa = new Homapape();
		hopa.setAut((List<PerPmsPes>)findid);
		return hopa.getAut();
	}

	/**调试员可以访问的员工权限页面信息
	 * @param empid 
	 * @return
	 */
	public List<Authority> getAuthority(Integer empid) {
		Optional<PerPmsEmp> findid = ped.findById(empid);
		Homapape hopa = new Homapape();
		hopa.setAut(findid.get().getPerPmsYQs(),findid.get());
		return hopa.getAut();
	}

	/**查询聊天信息
	 * @param i
	 * @return
	 */
	public List<Wle> getWle(Integer i) {
		Optional<PerPmsEmp> ppe = ped.findById(i);
		List<Wle> list = new ArrayList<>();
		int[] in = new int[30];
		int z = 0;
		int l = 0;
		A:for(PerKnoWle pkw : ppe.get().getPerKnoWles1()) {
			for(int j:in) {
				if(pkw.getPerPmsEmp2().getEmpid()==j) {
					break A;
				};
			}
			l = pkw.getPerPmsEmp2().getEmpid();
			in[z] = l;
			z++;
			list.add(new Wle(ppe.get(),l));
		}
		return list ;
	}
}
